#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cmplx.h"
#include "filter.h"
#include "specfunc.h"


void save2txt(typedsp *x, typedsp *y, long n, char* fn)
{
	FILE *f;
	long k;
	f = fopen(fn, "w");
	if(!f)
		return;
	for(k = 0; k < n; k++)
	{
		fprintf(f, "%.8E %.8E\n", x[k], y[k]);
	}
	fclose(f);
}


int main(void)
{
	
	/*typedsp k, K;
	k = 0.93;
	K = ellipSn(0.6, k);
	
	printf("K = %.6f\n", K);
	*/

	typedsp a[6], b[6], w[1024], amp[1024];
	complex h[1024];
	long n;

	cheby2Norm(30.0, 5, b, a);

	w[0] =1E-4;
	for(n = 1; n < 1024; n++)
		w[n] = w[n-1]*1.012;

	freqs(b,6,a,6,w,1024,h);

	for(n = 0; n < 1024; n++)
	{
		amp[n] = 10.0*log10(absSqrCmplx(h[n]));
		printf("%.4f %.4f\n", w[n], amp[n]);
	}
	
	save2txt(w,amp,1024,"data/cheby2Norm.txt");
	system("Pause");
	return 0;
}


